﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Data.OleDb;

public partial class admin_channel : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    //生成树
    public void getTree() {
        StringBuilder sb = new StringBuilder();
        OleDbConnection conn = DB.conn();
        OleDbCommand comm = null;
        OleDbCommand commTemp = null;
        try
        {
            conn.Open();
            comm = new OleDbCommand();
            comm.Connection = conn;
            comm.CommandText = "select * from channel order by show_order";
            OleDbDataAdapter da = new OleDbDataAdapter();
            da.SelectCommand = comm;
            DataTable dt = new DataTable();
            da.Fill(dt);
            if (dt.Rows.Count > 0) {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string fatherid = "";
                    string fathername = "";
                    fatherid = dt.Rows[i]["father_id"].ToString();
                    fathername = "";
                    if (!"".Equals(fatherid) && !"1".Equals(fatherid)) { 
                        //获取父栏目名称
                        commTemp = new OleDbCommand();
                        commTemp.Connection = conn;
                        commTemp.CommandText = "select name from channel where channel_id=" + fatherid;
                        OleDbDataReader reader = commTemp.ExecuteReader();
                        fathername = "无上级栏目";
                        if (reader != null && reader.HasRows)
                        {
                            reader.Read();
                            if (reader.GetString(0).Trim().Length>0)
                                fathername = reader.GetString(0);
                        }
                    }
                    sb.Append("tree.nodes[\""+fatherid+"_"+dt.Rows[i]["channel_id"].ToString()+"\"] = \"text:"
                        +dt.Rows[i]["name"].ToString()+";method:sa('"+fatherid+"','"
                        +fathername+"','"+dt.Rows[i]["channel_id"].ToString()+"','"
                        +dt.Rows[i]["name"].ToString()+"','"+dt.Rows[i]["show_Order"].ToString()+"','"
                        +dt.Rows[i]["url"].ToString()+"','"+dt.Rows[i]["is_show"].ToString()+"','"
                        +dt.Rows[i]["img"].ToString()+"','"+dt.Rows[i]["pageLocation"].ToString()+"')\";  ");
                }
            }
            Response.Write(sb.ToString());
        }
        catch (Exception error)
        {
            Response.Write(error.ToString());
        }
        finally {
            if (comm != null) {
                comm.Dispose();
            }
            conn.Close();
        }
    }
}
